unit Shapes;

interface

uses
  SysUtils, Windows, Graphics;

type
  TFPoint = record
    x, y: real;
  end;

  TShape = class( TObject )
      pos: TFPoint;
      //vx, vy: real;
      Color: TColor;
      Procedure Draw( Canvas: TCanvas ); virtual; abstract;
      procedure Move( dL: integer );// virtual; abstract;
      function Collision( w, h: integer ): boolean; virtual; abstract;
  end;
  TCircle = class( TShape )
      R: integer;
      procedure Draw( Canvas: TCanvas ); override;
      //procedure Move( dL: integer ); override;
      function Collision( w, h: integer ): boolean; override;
    public
      constructor Create( rnx, rny, rnr: integer );
  end;
  TRectangle = class( TShape )
      l: integer;
      procedure Draw( Canvas: TCanvas ); override;
      //procedure Move( dL: integer ); override;
      function Collision( w, h: integer ): boolean; override;
    public
      constructor Create( rnx, rny, rnl: integer ); overload;
      constructor Create( position: TFPoint; a: integer ); overload;
  end;

  


implementation

  function FPoint( x, y: real ): TFPoint;
  begin
    Result.x := x;
    Result.y := y;
  end;

 //////////////////////////// CREATE \\\\\\\\\\\\\\\\\\\\\\\\\\
  constructor TCircle.Create( rnx, rny, rnr: integer );
  begin
    Color := RGB( random(255),random(255),random(255) );
    pos := FPoint( random( rnx ), random( rny ) );
    r := random( rnr );
  end;
  constructor TRectangle.Create( rnx, rny, rnl: integer );
  begin
    Color := RGB( random(255),random(255),random(255) );
    pos := FPoint( random( rnx ), random( rny ) );
    l := random( rnl );
  end;
  constructor TRectangle.Create( position: TFPoint; a: integer );
  begin
    Color := clWhite;
    pos := position;
    l := a;
  end;
 ///////////////////////////END CREATE\\\\\\\\\\\\\\\\\\\\\\\\\

 ///////////////////////////DRAW\\\\\\\\\\\\\\\\\\\\\\\\\
  procedure TCircle.Draw( Canvas: TCanvas );
  begin
    Canvas.Brush.Color := Color;
    Canvas.Ellipse( round( pos.x ) - r, round( pos.y ) - r,
                    round( pos.x ) + r, round( pos.y ) + r );
  end;
  procedure TRectangle.Draw( Canvas: TCanvas );
  begin
    Canvas.Brush.Color := Color;
    Canvas.Rectangle( round( pos.x ), round( pos.y ),
                      round( pos.x ) + l, round( pos.y ) + l );
  end;
 ///////////////////////////END DRAW\\\\\\\\\\\\\\\\\\\\\\\\\

 ///////////////////////////COLLISION\\\\\\\\\\\\\\\\\\\\\\\\\
  function TCircle.Collision( w, h: integer ): boolean;
  begin
    result := false;
    if (round(pos.x - r) < 0) or
       (round(pos.x + r) > w) or
       (round(pos.y - r) < 0) or
       (round(pos.y + r) > h) then
      result := true;
  end;

  function TRectangle.Collision( w, h: integer ): boolean;
  begin
    result := false;
    if (round(pos.x    ) < 0) or
       (round(pos.x + l) > w) or
       (round(pos.y    ) < 0) or
       (round(pos.y + l) > h) then
      result := true;
  end;
 ///////////////////////////END COLLISION\\\\\\\\\\\\\\\\\\\\\\\\\

 ///////////////////////////MOVE\\\\\\\\\\\\\\\\\\\\\\\\\
  procedure TShape.Move( dL: Integer );
  begin
    pos.x := pos.x + random( dL+1 ) - dL/2;
    pos.y := pos.y + random( dL+1 ) - dL/2;
  end;
 ///////////////////////////END MOVE\\\\\\\\\\\\\\\\\\\\\\\\\
end.
 